package com.old.people.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.old.people.entities.Appraisal;
import com.old.people.entities.Disease;
import com.old.people.entities.OldPeople;
import com.old.people.entities.OrderServiceServicer;
import com.old.people.entities.ServiceServicer;
import com.old.people.service.UserService;

@RestController
@RequestMapping("/oldpeopleservice")
public class UserController {
	@Autowired
	private UserService userService;

	@RequestMapping("/selectOldpeople")
	@ResponseBody
	public OldPeople selectOldpeople(String account_id) {
		return userService.select(account_id);
	}

	@RequestMapping("/updateOldpeople")
	@ResponseBody
	public boolean updateOldpeople(String oldpeople_id, String oldpeople_name, String oldpeople_sex,
			String oldpeople_idcard, String oldpeople_address, String oldpeople_tel, String oldpeople_description,
			String oldpeople_familytel) {
		return userService.updateOldpeople(oldpeople_id, oldpeople_name, oldpeople_sex, oldpeople_idcard,
				oldpeople_address, oldpeople_tel, oldpeople_description, oldpeople_familytel);
	}

	@RequestMapping("/getAppraisals")
	@ResponseBody
	public List<Appraisal> getAppraisal(String account_id, Integer page) {
		int begin = page * 10 - 10;
		if (begin < 0) {
			begin = 0;
		}
		return userService.getAppraisal(account_id, begin);
	}

	@RequestMapping("/getAppraisalPages")
	@ResponseBody
	public Integer getAppraisalPage(String account_id) {
		int sum = (int) userService.getAppraisalSum(account_id);
		int page = 0;
		if (sum % 10 > 0) {
			page = sum / 10 + 1;
		} else {
			page = sum / 10;
		}
		return page;
	}

	@RequestMapping("/getdiseases")
	@ResponseBody
	public List<Disease> getdiseases(String account_id) {
		return userService.getdiseases(account_id);
	}

	@RequestMapping("/getOrderServiceServicer")
	@ResponseBody
	public List<OrderServiceServicer> getOrderServiceServicer(String account_id, int page) {
		int begin = page * 10 - 10;
		if (begin < 0) {
			begin = 0;
		}
		return userService.getOrderServiceServicer(account_id, begin);
	}

	@RequestMapping("/getOrderServiceServicerSum")
	@ResponseBody
	public int getOrderServiceServicerSum(String account_id) {
		int sum = (int) userService.getOrderServiceServicerSum(account_id);
		int page = 0;
		if (sum % 10 > 0) {
			page = sum / 10 + 1;
		} else {
			page = sum / 10;
		}
		return page;
	}

	@RequestMapping("/updateOrder")
	@ResponseBody
	public boolean updateOrder(String order_id, String order_status) {
		return userService.updateOrder(order_id, order_status);
	}

	@RequestMapping("/updateOrders")
	@ResponseBody
	public boolean updateOrders(String order_id, String order_completetime) {
		return userService.updateOrders(order_id, order_completetime);
	}

	@RequestMapping("/insertAppraisal")
	@ResponseBody
	public boolean insertAppraisal(String appraisal_id, String appraisal_grade, String appraisal_content,
			String account_id, String order_id) {
		return userService.insertAppraisal(appraisal_id, appraisal_grade, appraisal_content, account_id, order_id);
	}
	
	@RequestMapping("/getServices")
	@ResponseBody
	public List<ServiceServicer> getServices(Integer page) {
		int begin = page * 10 - 10;
		if (begin < 0) {
			begin = 0;
		}
		return userService.getService(begin);
	}

	@RequestMapping("/getServicePages")
	@ResponseBody
	public int getServicePage() {
		int sum = (int) userService.getServiceSum();
		int page = 0;
		if (sum % 10 > 0) {
			page = sum / 10 + 1;
		} else {
			page = sum / 10;
		}
		return page;
	}

	@RequestMapping("/selectServices")
	@ResponseBody
	public List<ServiceServicer> selectService(String service_name) {
		return userService.selectService(service_name);
	}

	@RequestMapping("/insertOrders")
	@ResponseBody
	public boolean insertOrder(String order_id, String order_createtime, String order_scheduledtime,
			String order_completetime, String order_status, String order_price, String servicer_id, String oldpeople_id,
			String account_id) {
		return userService.insertOrder(order_id, order_createtime, order_scheduledtime, order_completetime, order_status, order_price, servicer_id, oldpeople_id, account_id);
	}
	
	@RequestMapping("/getOldpeopleId")
	@ResponseBody
	public String getOldpeopleId(String account_id) {
		return userService.getOldpeopleId(account_id);
	}
	
	@RequestMapping("/insertUserFunds")
	@ResponseBody
	public boolean insertUserFunds(String funds_id, String funds_type, String funds_amount, String funds_date,
			String account_id) {
		return userService.insertUserFunds(funds_id, funds_type, funds_amount, funds_date, account_id);
	}
	
	@RequestMapping("/getAccount")
	@ResponseBody
	public String getAccount(String holder_id) {
		return userService.getAccount(holder_id);
	}
}
